#!/usr/bin/python
# -*- coding:utf-8 -*-
# @author  : Chestnut
# @time    : 2025/6/26 17:16
# @function: What can I do.
# @version : V1

import pandas
import os
import tkinter
from tkinter import filedialog,ttk


class CsvCut:
    def __init__(self):
        pass

    def read_file(self):
        try:
            self.file.close()
        except:
            pass
        askfile = filedialog.askopenfilename()
        if askfile != "":
            f1 = pandas.read_csv(askfile,encoding="gb2312",on_bad_lines='warn')
            self.file = f1
            self.file_name.set(askfile)
        else:
            self.file = None
            self.file_name.set(askfile)
            pass

    def CsvCut(self):
        print(self.file)

    def main_window(self):
        root = tkinter.Tk()
        self.file_name = tkinter.StringVar()
        root.title("Csv Cuter")
        tkinter.Label(root,text="选择文件").grid(row=0, column=0)
        self.e1 = tkinter.Entry(root,width=50,textvariable=self.file_name)
        self.t1 = tkinter.Text(root)
        tkinter.Button(root,text="Browse",command=self.read_file).grid(row=0, column=2)
        tkinter.Button(root,text="Start",command=self.CsvCut,width=80).grid(row=3, column=0,columnspan=3)
        self.p1 = ttk.Progressbar(root, orient=tkinter.HORIZONTAL,length=550,mode='determinate')
        root.bind("<Return>",self.CsvCut)
        self.e1.grid(row=0, column=1)
        self.t1.grid(row=1, column=0,columnspan=3)
        self.p1.grid(row=2,column=0,columnspan=3)
        root.mainloop()


myapp = CsvCut()
myapp.main_window()